package heima3_2.cn.osc.base;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import heima3_2.cn.osc.constant.ResultState;
import heima3_2.cn.osc.ui.view.ContentPager;


/**
 * Created by Administrator on 2016/12/7 0007.
 * 所有片段的基类
 */

public abstract class BaseFragment extends Fragment {
    protected Context context;

    public ContentPager contentPager;
    public ViewGroup mContainer;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context=getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(final LayoutInflater inflater,
                             @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
                    this.mContainer=container;
        //片段的界面
        if(contentPager==null) {
            contentPager = new ContentPager(getActivity()) {
                @Override
                protected ResultState onLoadData() {
                    //todo
//                int state=onLoadSubData();
                    return onLoadSubData();
                }

                //创建片段的成功界面模块的方法
                @Override
                protected View onCreateSuccessView() {
                    //todo
                    View successView = onCreateSubSuccessView(inflater,container);
                    return successView;
                }
            };
        }
        return contentPager;
    }

    //加载数据的方法 ，由于BaseFragment不能决定每个模块片段如何取加载数据，url不同，数据也不同 ，应该抽象出去，由子类来实现
    protected abstract ResultState onLoadSubData() ;

    //由于BaseFragment不能决定每个模块片段的成功界面，所以抽象出去，由子类来实现
    protected abstract View onCreateSubSuccessView(LayoutInflater inflater,
                                                   ViewGroup container) ;
}
